// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-10-20 20:45:06
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:11:14
 * @FilePath: \SGFEM\Import\BDFImport\test\Material\MAT2ParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Material/MAT2Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Material/IAnisotropic2DMaterialService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class MAT2ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (MAT2ParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "MAT2           27965000. 664000.        2655000.        1250000.  7.85-9+0000050",
                                       "+0000050                                         150000. 150000.   6000.+0000051",
                                       "+0000051        " };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseMAT2 (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::Anisotropic2DMaterial data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IAnisotropic2DMaterialService> ()->FindById (2, data)
                 == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_id == 2);
    ASSERT_NEAR (data.m_G[0], 7965000., TOLERANCE);
    ASSERT_NEAR (data.m_G[1], 664000., TOLERANCE);
    ASSERT_NEAR (data.m_G[2], 0., TOLERANCE);
    ASSERT_NEAR (data.m_G[3], 2655000., TOLERANCE);
    ASSERT_NEAR (data.m_G[4], 0., TOLERANCE);
    ASSERT_NEAR (data.m_G[5], 1250000., TOLERANCE);
    ASSERT_NEAR (data.m_rho, 7.85e-9, TOLERANCE);

    ASSERT_NEAR (data.m_Ai[0], 0, TOLERANCE);
    ASSERT_NEAR (data.m_Ai[1], 0, TOLERANCE);
    ASSERT_NEAR (data.m_Ai[2], 0, TOLERANCE);
    ASSERT_NEAR (data.m_tref, 0, TOLERANCE);
    ASSERT_NEAR (data.m_ge, 0, TOLERANCE);
    ASSERT_NEAR (data.m_ST, 150000., TOLERANCE);
    ASSERT_NEAR (data.m_SC, 150000., TOLERANCE);
    ASSERT_NEAR (data.m_SS, 6000., TOLERANCE);
    ASSERT_NEAR (data.m_mcsid, 0, TOLERANCE);
    ASSERT_TRUE (data.m_domainId == 1);
}
